package com.company.service.impl;

import com.company.dao.UserDao;
import com.company.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @ClassName UserServiceImpl
 * @Description
 */
public class UserServiceImpl implements UserService {

    private UserDao userDao;

    public UserServiceImpl() {
    }

    public UserServiceImpl(UserDao userDao) {
        this.userDao = userDao;
        System.out.println("userService 有参构造方法注入");
    }

    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
        System.out.println("userService set()方式注入");
    }

    @Override
    public void save() {
        /*  如果能够通过 set 方法进行注入，那么就不需要从 Spring 容器中进行获取了，这里就可以通过私有属性进行调用  save 方法；
            但是需要在 Spring 配置文件中进行配置 */
        /*ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserDao userDao = (UserDao) app.getBean("userDao");*/
        System.out.println(userDao.toString());
        userDao.save();
    }
}
